package Callable;

//编写代码, 基于 Callable 实现 1+2+3+...+1000

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Long> callable = new Callable<>() {
            @Override
            public Long call() throws Exception {
                long sum = 0;
                for (int i = 1; i <= 1000000; i++) {
                    for (int j = 1; j <= 10000; j++) {
                        sum += j;
                    }
                }
                return sum;
            }
        };

        FutureTask<Long> futureTask = new FutureTask<>(callable);

        Thread thread = new Thread(futureTask);
        thread.start();
        System.out.println(futureTask.get());//产生阻塞
        System.out.println("main");
    }
}
